package com.android.backend.util;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
 * @Auther:kiwi
 * @Date: 2019/6/3 16:20
 */
public class JSONChange {
  /*
 * 001.json转换成对象
 * @param:传入对象，json字符串
 * @return:Object
 */
        public static Object jsonToObj(Object obj,String jsonStr) throws JsonParseException, JsonMappingException, IOException {
            ObjectMapper mapper = new ObjectMapper();
            return obj = mapper.readValue(jsonStr, obj.getClass());
        }
        /*
         * 002.对象转换成json
         * @param:传入对象
         * @return:json字符串
         */
        public static String objToJson(Object obj) throws JsonProcessingException {
            ObjectMapper mapper = new ObjectMapper();
            return mapper.writeValueAsString(obj);
        }
}
